﻿using System.Windows;
using GMap.NET.WindowsPresentation;
using System;
using GMap.NET;

namespace InteractiveMapApp.CustomMarkers
{
    /// <summary>
    /// Interaction logic for auckCircle.xaml
    /// </summary>
    public partial class auckCircle
    {
        GMapMarker Marker;
        MainWindow MainWindow;
        double iconOrigHeight;
        double iconOrigWidth;

        public auckCircle(MainWindow window, GMapMarker marker)
        {
            this.InitializeComponent();
            this.MainWindow = window;
            this.Marker = marker;
            this.AllowDrop = true;
            iconOrigHeight = 880;
            iconOrigWidth = 700;
            //TODO : is it possible to change anchor point of this? from bottom left/right ot CENTER
            this.Unloaded += new RoutedEventHandler(auckCircle_Unloaded);
            this.Loaded += new RoutedEventHandler(auckCircle_Loaded);
            this.DragOver += new DragEventHandler(auckCircle_DragOver);
            this.DragLeave += new DragEventHandler(auckCircle_DragLeave);
            MainWindow.MainMap.OnMapZoomChanged += new MapZoomChanged(MainMap_OnMapZoomChanged);
            //this.MouseMove += new MouseEventHandler(auckCircle_MouseMove);
            //this.MouseEnter += new MouseEventHandler(MarkerControl_MouseEnter);
            //this.MouseLeave += new MouseEventHandler(MarkerControl_MouseLeave);
            this.SizeChanged += new SizeChangedEventHandler(auckCircle_SizeChanged);
            //this.MouseUp += new MouseButtonEventHandler(auckCircle_MouseUp);
            //MainWindow.MainMap.MouseDown += new MouseButtonEventHandler(mainMap_mouseDown);
            //MainWindow.MainMap.MouseWheel += new MouseWheelEventHandler(MainMap_MouseWheel);
        }

        void MainMap_OnMapZoomChanged()
        {
            //switch (Convert.ToInt32(MainWindow.MainMap.Zoom))
            //{
            //    case 10:
            //        icon.Height = iconOrigHeight;
            //        icon.Width = iconOrigWidth;

            //        break;

            //    case 11:
            //        icon.Height = iconOrigHeight * 2;
            //        icon.Width = iconOrigWidth * 2;
            //        break;

            //    case 12:
            //        icon.Height = iconOrigHeight * 3;
            //        icon.Width = iconOrigWidth * 3;
            //        break;

            //    case 16:
            //        icon.Height = iconOrigHeight * 6;
            //        icon.Width = iconOrigWidth * 6;
            //        break;

            //    default:
            //        break;
            //}
        }

        void auckCircle_DragOver(object sender, DragEventArgs e)
        {
            MainWindow.aucklandCircleZoneIsBeingDraggedOver = true;
        }

        void auckCircle_DragLeave(object sender, DragEventArgs e)
        {
            MainWindow.aucklandCircleZoneIsBeingDraggedOver = false;
        }

        void auckCircle_Loaded(object sender, RoutedEventArgs e)
        {
            if (icon.Source.CanFreeze)
            {
                icon.Source.Freeze();
            }
        }

        void auckCircle_Unloaded(object sender, RoutedEventArgs e)
        {
            this.Unloaded -= new RoutedEventHandler(auckCircle_Unloaded);
            this.Loaded -= new RoutedEventHandler(auckCircle_Loaded);
            this.SizeChanged -= new SizeChangedEventHandler(auckCircle_SizeChanged);
            //this.MouseEnter -= new MouseEventHandler(MarkerControl_MouseEnter);
            //this.MouseLeave -= new MouseEventHandler(MarkerControl_MouseLeave);
            this.DragOver -= new DragEventHandler(auckCircle_DragOver);
            this.DragLeave -= new DragEventHandler(auckCircle_DragLeave);
            MainWindow.MainMap.OnMapZoomChanged -= new MapZoomChanged(MainMap_OnMapZoomChanged);
            Marker.Shape = null;
            icon.Source = null;
            icon = null;
        }

        void auckCircle_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.Marker.Offset = new Point(-e.NewSize.Width / 2, -e.NewSize.Height);
        }
    }
}